<?php

class admin_menu_item_m_core extends a_base_model_datamapper{
    public function  __construct($id = NULL) {
        $this->table = "admin_menu_items";
        parent::__construct($id);
    }

    public  function get_items(){
        $objs = $this->query("SELECT * FROM modules
            INNER JOIN admin_menu_items ai ON ai.module_id = modules.id ");
        return $this->_grouped_items($objs);

    }
    protected function _grouped_items(admin_menu_item_m_core $objs){
        $grouped_items = array();
        foreach($objs as $o){
            $name = $o->get_module_obj()->name;
            $friendly_name = $o->get_module_obj()->friendly_name;
            if(!isset ($grouped_items[$friendly_name])){
                $grouped_items[$friendly_name] = array();
            }
            $data = $o->convert_to_simple_data();
            $data->module_name           = $name;
            $data->module_friendly_name  = $friendly_name;
            $data->module_desc          = $o->get_module_obj()->description;

            $grouped_items[$friendly_name][] = $data;
        }
        return $grouped_items;
    }
    public function get_module_obj(){
        $modules = Module_Extended::list_modules();
        if(count($modules)>0){
            return $modules[$this->module_id];
        }else{
            return NULL;
        }
    }
}
?>